#from pyweka.arff import *
import sys
sys.path.append("..")
import arff
from arff import *
import unittest


class testParserArffItem(unittest.TestCase):
    """
    test the read is all right
    """
    #resultdic = {}
    headbegin = "@relation 'classify-weka.filters.unsupervised.attribute.Remove-V-R1,9,19,44,52,59,66-67,76-77,84,87,91,94,97,101'"
    headend = "@data\n"
    line0 = """0,0.020235,0,0,0.019404,0.008421,0,0,0.061906,0.016964,0.040651,0.061901,0.65312,0,0,3"""
    line9 = """0,0.007444,0,0,0.048509,0.009638,0,0,0,0.076211,0.020867,0.061901,0.006907,0,0.654687,3"""
    line399 = """0,0.034433,0,0,0,0.067364,0,0,0,0.095449,0.032317,0,0,0,0,3"""
        
    def testReadValue(self):
        """
        the result should be in the format of
        dic['head']
        dic['datas']
        """
        result = parserArffItems("test.arff")
        self.assertEqual(result['datas'][0],self.line0)
        self.assertEqual(result['datas'][9],self.line9)
        self.assertEqual(result['datas'][399],self.line399)
        

    def testReadHead(self):
        """
        the head part value
        """
        result = parserArffItems("test.arff")
        self.assertEqual(result['head'].startswith(self.headbegin),True)
        self.assertEqual(result['head'].endswith(self.headend),True)

    def testReadCount(self):
        """
        the count of read item
        """
        result = parserArffItems("test.arff")
        self.assertEqual(len(result['datas']),400)

class testParserArffItemBadInput(unittest.TestCase):
    """
    for bad input should give the right coresponse
    """
    def testFileNotExist(self):
        self.assertRaises(arff.FileNotExistError,parserArffItems,"a")

class testParserArffGetAttr(unittest.TestCase):
    def testGetAttr(self):
        result = getAttrList("test.arff")
        self.assertEqual(len(result),16)
        self.assertEqual(result[0]['name'],"f0")
        self.assertEqual(result[0]['type'],"numeric")
        
        
if __name__ == "__main__":
    unittest.main()   
